package com.manage.web.editor;

import java.beans.PropertyEditorSupport;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class LocalDateEditor extends PropertyEditorSupport {
    
    private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
    
    @Override
    public void setAsText(String text) throws IllegalArgumentException {
        if (text != null && !text.trim().isEmpty()) {
            setValue(LocalDate.parse(text, FORMATTER));
        } else {
            setValue(null);
        }
    }
    
    @Override
    public String getAsText() {
        LocalDate value = (LocalDate) getValue();
        return value != null ? value.format(FORMATTER) : "";
    }
}
